/**
 * 填写苗木档案
 * Created by Wayne on 2015/7/17.
 */
define(function(require, exports, module) {
	'use strict';
	module.exports = function(app) {
		app.register.controller('filloutRecordCtrl', ['$scope', '$location', 'tempData', 'MHService', '$routeParams',
			function($scope, $location, tempData, MHService, $routeParams) {
				var toast = require('../services/mh-toast');
				$scope.record = tempData.data;
				if($scope.record==undefined) {
					$location.path('/feedManage');
				}
				// console.log($scope.record);
				var tempD = new Date($scope.record.starttime.time);
				$scope.start = (tempD.getFullYear()+'-'+(tempD.getMonth()+1)+'-'+tempD.getDate());
				tempD = new Date($scope.record.movetime.time);
				$scope.move = (tempD.getFullYear()+'-'+(tempD.getMonth()+1)+'-'+tempD.getDate());
				$scope.record.arrivaltime = new Date($scope.record.arrivaltime.time);
				$scope.record.planttime = new Date($scope.record.planttime.time);
				//提交信息
				$scope.postInfo = function() {
					tempD = new Date($scope.record.arrivaltime);
					if(tempD) {
						$scope.arrivaltime = tempD.getFullYear()+'-'+(tempD.getMonth()+1)+'-'+tempD.getDate();
					}
					tempD = new Date($scope.record.planttime);
					if(tempD) {
						$scope.planttime = tempD.getFullYear()+'-'+(tempD.getMonth()+1)+'-'+tempD.getDate();
					}
					var config = {
						url: MHService.URL.record_add_last,
						_req: {
							//基础信息
							id: $scope.record.id,
							name: $scope.record.rName,
							materialid: $scope.record.materialid,
							account: $scope.record.account,
							info: $scope.record.info,
							starttime: $scope.start,
							movetime: $scope.move,
							moveinfo: $scope.record.moveinfo,
							moveremark: $scope.record.moveremark,
							purchaseid: $scope.record.purchaseid,
							//添加信息
							arrivaltime: $scope.arrivaltime,
							planttime: $scope.planttime,
							checkinfo: $scope.record.checkinfo,
							plantinfo: $scope.record.plantinfo,
							scheme: $scope.record.scheme,
							plantremark: $scope.record.plantremark,
							workerid: $scope.record.workerid,
							resolveid: $scope.record.resolveid
						}
					}
					MHService.postReq(config, function(data) {
						toast.show('苗木档案填写成功。');
						$location.path('/feedManage')
					})
				}
				//重置
				$scope.delInfo = function() {
					$scope.record.arrivaltime = $scope.record.checkinfo = $scope.record.planttime = $scope.record.plantinfo =
					$scope.record.scheme = $scope.record.plantremark = $scope.record.workerid = $scope.record.resolveid = null;
					toast.show('已重置。');
				}
			}
		])
	}
})